package atri.mapper;

import atri.model.Recommend;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface RecommendMapper extends BaseMapper<Recommend> {
    @Select("select * from recommend where content LIKE '%${content}%'")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "user_id", property = "user_id"),
            @Result(column = "title", property = "title"),
            @Result(column = "content", property = "content"),
            @Result(column = "time", property = "time"),
            @Result(column = "star", property = "star"),
            @Result(column = "view_sum", property = "view_sum"),
            @Result(column = "img_url", property = "img_url")
    })
    List<Recommend> find_by_content(String content);

    @Select("select * from recommend where title LIKE '%${title}%'")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "user_id", property = "user_id"),
            @Result(column = "title", property = "title"),
            @Result(column = "content", property = "content"),
            @Result(column = "time", property = "time"),
            @Result(column = "star", property = "star"),
            @Result(column = "view_sum", property = "view_sum"),
            @Result(column = "img_url", property = "img_url")
    })
    List<Recommend> find_by_title(String title);
    @Select("SELECT * FROM recommend ORDER BY view_sum DESC LIMIT 10")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "user_id", property = "user_id"),
            @Result(column = "title", property = "title"),
            @Result(column = "content", property = "content"),
            @Result(column = "time", property = "time"),
            @Result(column = "star", property = "star"),
            @Result(column = "view_sum", property = "view_sum"),
            @Result(column = "img_url", property = "img_url")
    })
    List<Recommend> find_hot_10();

    @Select("SELECT * FROM recommend WHERE user_id = #{id}")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "user_id", property = "user_id"),
            @Result(column = "title", property = "title"),
            @Result(column = "content", property = "content"),
            @Result(column = "time", property = "time"),
            @Result(column = "star", property = "star"),
            @Result(column = "view_sum", property = "view_sum"),
            @Result(column = "img_url", property = "img_url")
    })
    List<Recommend> find_user_recommends(int id);

    @Select("SELECT * FROM recommend")
            @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "user_id", property = "user_id"),
            @Result(column = "title", property = "title"),
            @Result(column = "content", property = "content"),
            @Result(column = "time", property = "time"),
            @Result(column = "star", property = "star"),
            @Result(column = "view_sum", property = "view_sum"),
            @Result(column = "img_url", property = "img_url")
    })
    List<Recommend> find_recommends();
    
    @Delete("DELETE FROM comment WHERE user_id = #{f_id}")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "user_id", property = "user_id"),
            @Result(column = "title", property = "title"),
            @Result(column = "content", property = "content"),
            @Result(column = "time", property = "time"),
            @Result(column = "star", property = "star"),
            @Result(column = "view_sum", property = "view_sum"),
            @Result(column = "img_url", property = "img_url")
    })
    int delete_under_recommends(int f_id);

    @Select("select * from recommend where id = #{id}")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "user_id", property = "user_id"),
            @Result(column = "title", property = "title"),
            @Result(column = "content", property = "content"),
            @Result(column = "time", property = "time"),
            @Result(column = "star", property = "star"),
            @Result(column = "view_sum", property = "view_sum"),
            @Result(column = "img_url", property = "img_url")
    })
    Recommend find_by_id_new(int id);

    @Select("select * from recommend where category = #{category}")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "user_id", property = "user_id"),
            @Result(column = "title", property = "title"),
            @Result(column = "content", property = "content"),
            @Result(column = "time", property = "time"),
            @Result(column = "star", property = "star"),
            @Result(column = "view_sum", property = "view_sum"),
            @Result(column = "img_url", property = "img_url")
    })
    List<Recommend> find_by_category(String category);
    //通过文章标签筛选博客

    @Delete("DELETE FROM recommend WHERE user_id = #{id}")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "user_id", property = "user_id"),
            @Result(column = "title", property = "title"),
            @Result(column = "content", property = "content"),
            @Result(column = "time", property = "time"),
            @Result(column = "star", property = "star"),
            @Result(column = "view_sum", property = "view_sum"),
            @Result(column = "img_url", property = "img_url")
    })
    Boolean delete_by_user_id(int id);

    @Update("UPDATE recommend SET view_sum = view_sum + 1 WHERE id = #{id}")
    @Results({
            @Result(column = "id", property = "id"),
            @Result(column = "user_id", property = "user_id"),
            @Result(column = "title", property = "title"),
            @Result(column = "content", property = "content"),
            @Result(column = "time", property = "time"),
            @Result(column = "star", property = "star"),
            @Result(column = "view_sum", property = "view_sum"),
            @Result(column = "img_url", property = "img_url")
    })
    Boolean add_view(int id);
    @Select("SELECT LAST_INSERT_ID()")
    int find_new_id();
}
